package cn.tedu.luban.account.main.rpc;

import cn.tedu.luban.account.api.AccountApi;
import cn.tedu.luban.account.main.converter.AccountConverter;
import cn.tedu.luban.account.main.service.AccountAdminService;
import cn.tedu.luban.account.protocol.bo.AccountBO;
import cn.tedu.luban.account.protocol.dto.AccountDTO;
import cn.tedu.luban.account.protocol.param.AccountCreateParam;
import cn.tedu.luban.account.protocol.param.AccountPayParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class AccountApiImpl implements AccountApi {
    @Autowired
    private AccountAdminService accountAdminService;
    @Autowired
    private AccountConverter accountConverter;
    @Override public Long createAccount(AccountCreateParam accountCreateParam){
        return accountAdminService.saveAccount(accountCreateParam);
    }

    @Override public AccountDTO getAccount(Long userId) {
        AccountBO account = accountAdminService.getAccountByUserId(userId);
        return accountConverter.bo2dto(account);
    }

    @Override public Long mockPayment(AccountPayParam param) {
        log.info("接收到远程打款参数：{}",param);
        return accountAdminService.pay(param);
    }
}
